package com.jacobson.core.mvp

import android.content.Context
import android.view.ViewGroup

/**
 * ================================================
 *
 *  @author Wucz on 2018/10/9 14:52
 * ================================================
 */

abstract class EmptableListRecyclerAdapter<T>(context: Context) : ListRecyclerAdapter<T>(context) {
    abstract fun onCreateCustomViewHolder(parent: ViewGroup, viewType: Int): ViewHolder<T>
    abstract fun onCreateEmptyViewHolder(parent: ViewGroup): ViewHolder<T>

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder<T> {
        if (VIEW_TYPE_EMPTY == viewType) {
            return onCreateEmptyViewHolder(parent)
        }
        return onCreateCustomViewHolder(parent, viewType)
    }

    open fun isEmpty() = getCustomItemCount() == 0

    open fun getCustomItemCount() = getDataList().size

    override fun isUnusualPosition(position: Int): Boolean {
        return isEmpty() || super.isUnusualPosition(position)
    }


    companion object {
        private const val VIEW_TYPE_EMPTY = Integer.MAX_VALUE - 12
    }
}